package com.geek.novel.activity

import android.animation.Animator
import android.animation.ValueAnimator
import android.os.Bundle
import com.geek.novel.R
import com.geek.novel.activity.base.BaseActivity
import com.geek.novel.activity.main.MainActivity
import kotlinx.android.synthetic.main.activity_welcome.*

/**
 * 欢迎界面,展示初次安装页面，也可以做广告
 */
class WelcomeActivity : BaseActivity() {

	private lateinit var welAnimator:ValueAnimator
	
	override fun onCreate(savedInstanceState: Bundle?) {
		super.onCreate(savedInstanceState)
		setContentView(R.layout.activity_welcome)
	}

	override fun initData(params: Bundle?){
		welAnimator = ValueAnimator.ofFloat(1f, 0f).setDuration(800)
		welAnimator.startDelay = 200

		welAnimator.addUpdateListener { animation ->
			val alpha = animation.animatedValue as Float
			iv_bg.alpha = alpha
			iv_icon.alpha = alpha
			tv_intro.alpha = 1f - alpha
		}
		welAnimator.addListener(object : Animator.AnimatorListener {
			override fun onAnimationStart(animation: Animator) {}
			override fun onAnimationEnd(animation: Animator) {
				startActivityByAnim(this@WelcomeActivity, MainActivity::class.java)
				finish()
			}

			override fun onAnimationCancel(animation: Animator) {}
			override fun onAnimationRepeat(animation: Animator) {}
		})
	}


	override fun firstRequest(params: Bundle?) {
		welAnimator.start()
	}
}
